mtcars veri setini kullananarak basit bir bar grafiği
elde edelim.cylnlibrary(ggplot2)
library(plotly) # interaktif grafikler için
library(dplyr) # veri düzenleme için
table(mtcars$cyl)
##
## 4 6 8
## 11 7 14
## Warning: The following aesthetics were dropped during statistical transformation: fill
## ℹ This can happen when ggplot fails to infer the correct grouping structure in
## the data.
## ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
## variable into a factor?
data %>%
plot_ly(x=~değişken,
y=~değişken)
plot_ly(data,
x=~değişken,
y=~değişken)
bar <- mtcars %>%
mutate(cyl = as.factor(cyl)) %>%
count(cyl) %>% # Frekans tablosu oluştur
plot_ly(x=~cyl,
y=~n,
color=~cyl)
.pull-left[
bar1 <- bar %>%
add_bars(width=0.5) %>% # bar genişliği
layout(title="mtcars veri seti ile
örnek bar grafiği",
xaxis = list(title="Slindir Sayısı "),
yaxis = list(title = "Frekans"))
.pull-right[
mtcars veri setini kullananarak basit bir bar grafiği
elde edelim.cyl (vites türüne göre
gruplandırma ile am )nmtcars %>%
mutate(cyl = as.factor(cyl),
am = as.factor(am)) %>%
count(cyl, am)
## cyl am n
## 1 4 0 3
## 2 4 1 8
## 3 6 0 4
## 4 6 1 3
## 5 8 0 12
## 6 8 1 2
.pull-left[
bar2 <- mtcars %>%
mutate(cyl = as.factor(cyl),
am = as.factor(am)) %>%
count(cyl, am) %>%
mutate(am=recode(am,
`0`= "Otomatik", `1`="Manual")) %>%
plot_ly(x=~cyl,
y=~n,
color=~am)
.pull-left[
.pull-left[
bar3 <- bar2 %>%
layout(title="mtcars veri seti ile
örnek bar grafiği",
yaxis = list(title="Slindir Sayısı "),
xaxis = list(title = "Frekans"),
barmode="stack")
.pull-left[
diamonds veri setinde price değişkeninin
histogramıhist1 <- diamonds %>%
plot_ly() %>%
add_histogram(x=~price)
hist2 <- diamonds %>%
plot_ly() %>%
add_histogram(x=~price) %>%
layout(bargap=0.1)
hist3 <- diamonds %>%
plot_ly(x=~price) %>%
add_histogram(nbinsx = 50, color=I("green")) %>%
layout(bargap=0.1)
hist4 <-
diamonds %>%
plot_ly() %>%
add_histogram(x=~price,
xbins = list(start=0, end=20000, size=2000)) %>%
layout(bargap=0.1)
hist5 <- diamonds %>%
plot_ly() %>%
add_histogram(x=~cut)
hist6 <- diamonds %>%
plot_ly() %>%
add_histogram(x=~cut, color=~clarity)
storms data setini kullanarak yıllara göre fırtına
türlerinin gözleneme sayılarıstorm_n <- storms %>%
count(year, status)
storm_n
## # A tibble: 138 × 3
## year status n
## <dbl> <chr> <int>
## 1 1975 hurricane 23
## 2 1975 tropical depression 30
## 3 1975 tropical storm 33
## 4 1976 hurricane 22
## 5 1976 tropical depression 10
## 6 1976 tropical storm 20
## 7 1977 hurricane 20
## 8 1977 tropical depression 16
## 9 1977 tropical storm 17
## 10 1978 hurricane 5
## # … with 128 more rows
.pull-left[
cizgi1 <- ggplot(storm_n,
aes(x=year, y= n, color=status))+
geom_line()
.pull-right[
cizgi1
ggplotly(cizgi1)
.pull-left[
cizgi2 <- storm_n %>%
plot_ly(x=~year, y=~n) %>%
add_lines(color=~status)
.pull-right[
.pull-left[
kutu1 <- ggplot(diamonds,aes(price)) +
geom_boxplot()
kutu1
.pull-right[
kutu2<- diamonds %>%
plot_ly() %>%
add_boxplot(x=~price,
boxpoints = "outliers")
kutu2
.pull-left[ - Grafik birleştirme işlemi subplot
hist <- diamonds %>%
plot_ly() %>%
add_histogram(x=~price)
kutu <- diamonds %>%
plot_ly() %>%
add_boxplot(x=~price,
boxpoints = "outliers")
comb <- subplot(hist, kutu , nrows = 2,
shareX = TRUE) %>%
hide_legend()
.pull-right[
library(gapminder)
gapminder %>%
str()
## tibble [1,704 × 6] (S3: tbl_df/tbl/data.frame)
## $ country : Factor w/ 142 levels "Afghanistan",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ continent: Factor w/ 5 levels "Africa","Americas",..: 3 3 3 3 3 3 3 3 3 3 ...
## $ year : int [1:1704] 1952 1957 1962 1967 1972 1977 1982 1987 1992 1997 ...
## $ lifeExp : num [1:1704] 28.8 30.3 32 34 36.1 ...
## $ pop : int [1:1704] 8425333 9240934 10267083 11537966 13079460 14880372 12881816 13867957 16317921 22227415 ...
## $ gdpPercap: num [1:1704] 779 821 853 836 740 ...
LifeExp ~ gdpPercap ilişkisi.pull-left[
.pull-right[
.pull-left[
sacilim2 <- gapminder %>%
filter(year==2002) %>%
plot_ly() %>%
add_markers(x=~gdpPercap, y=~lifeExp) %>%
layout(title="Plotly SSaçılım Grafiği",
xaxis=list(title="Kişi Başına
GBT(log ölçeğinde)", type="log"),
yaxis=list(title= "Bekelenen Ömür")) %>%
hide_legend()
.pull-right[
sacilim2
sacilim3 <- gapminder %>%
plot_ly() %>%
add_markers(x=~gdpPercap, y=~lifeExp,
frame=~year) %>%
layout(title="Plotly SSaçılım Grafiği",
xaxis=list(title="Kişi Başına
GBT(log ölçeğinde)", type="log"),
yaxis=list(title= "Bekelenen Ömür"))
sacilim3